package com.conf;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;

@Component
public class JedisConfig {

    //数据库地址
    private static String address;
    //    //密码
//    private static String password;
    //选择数据库 (一般为1-15)
    private static int index;

    @Value("${spring.redis.host}")
    public void setAddress(String address) {
        System.out.println("address = " + address);
        JedisConfig.address = address;
    }

//    @Value("${spring.redis.password}")
//    public void setPassword(String password) {
//        System.out.println("password = " + password);
//        JedisConfig.password = password;
//    }

    @Value("${spring.redis.database}")
    public void setIndex(String index) {
        System.out.println("index = " + index);
        JedisConfig.index = Integer.parseInt(index);
    }

    public static Jedis getJedis() {
        Jedis jedis = new Jedis(address, 6379);
//        jedis.auth(password);
        jedis.select(index);
        return jedis;
    }


}
